package dobest.ray.com.jiongjiong.activity.mine;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.facebook.drawee.view.SimpleDraweeView;

import dobest.ray.com.jiongjiong.R;
import dobest.ray.com.jiongjiong.activity.BaseFragment;
import dobest.ray.com.jiongjiong.activity.mumingleshi.BindDeviceListActivity;
import dobest.ray.com.jiongjiong.views.NavigationBar;
import me.nereo.multi_image_selector.MultiImageSelectorActivity;

/**
 * Created by Ray on 2016/3/16.
 * https://github.com/ray0807
 * 行动起来
 */
public class MineFragment extends BaseFragment implements View.OnClickListener {
    private NavigationBar navi;
    private SimpleDraweeView sdv_photo;
    /**
     * activity 实例
     */
    private Activity mActivity;
    private RelativeLayout rl_bind;
    private RelativeLayout rl_user_base_info;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mActivity = getActivity();
        return inflater.inflate(R.layout.fragment_mine, container, false);
    }

    @Override
    protected void findViews(View view) {
        navi = (NavigationBar) view.findViewById(R.id.navi);
        navi.setTitle("我的信息");
        sdv_photo = (SimpleDraweeView) view.findViewById(R.id.sdv_photo);
        rl_bind = (RelativeLayout) view.findViewById(R.id.rl_bind);
        rl_user_base_info = (RelativeLayout) view.findViewById(R.id.rl_user_base_info);
    }

    @Override
    protected void init() {
        sdv_photo.setImageURI(Uri.parse("http://www.cnsc8.com/res/tupian_201403/Big_Pic/jBaWwaVTmu.jpg"));
    }

    @Override
    protected void addListeners() {
        rl_bind.setOnClickListener(this);
        rl_user_base_info.setOnClickListener(this);
        sdv_photo.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        Intent it = null;
        switch (v.getId()) {
            case R.id.rl_bind:
                it = new Intent(mActivity, BindDeviceListActivity.class);
                break;
            case R.id.rl_user_base_info:
                it = new Intent(mActivity, BaseUserInfoActivity.class);
                break;
            //拍照
            case R.id.sdv_photo:
                takePic();
                break;
        }
        if (it != null) {
            mActivity.startActivity(it);
        }
    }

    private void takePic(){

        int selectedMode = MultiImageSelectorActivity.MODE_SINGLE;//单张
        //selectedMode = MultiImageSelectorActivity.MODE_MULTI;//多张
        Intent intent = new Intent(mActivity, MultiImageSelectorActivity.class);
        // 是否显示拍摄图片
        intent.putExtra(MultiImageSelectorActivity.EXTRA_SHOW_CAMERA, true);
        // 最大可选择图片数量
//        intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_COUNT, maxNum);
        // 选择模式
        intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE, selectedMode);
        // 默认选择
//        if(mSelectPath != null && mSelectPath.size()>0){
//            intent.putExtra(MultiImageSelectorActivity.EXTRA_DEFAULT_SELECTED_LIST, mSelectPath);
//        }
        startActivityForResult(intent, 2);

    }
//
//    @Override
//    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//        if(requestCode == REQUEST_IMAGE){
//            if(resultCode == RESULT_OK){
//                mSelectPath = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT);
//                StringBuilder sb = new StringBuilder();
//                for(String p: mSelectPath){
//                    sb.append(p);
//                    sb.append("\n");
//                }
//                mResultText.setText(sb.toString());
//            }
//        }
//    }
}
